Release 10.1A: OpenEdge Development:
Progress 4GL Handbook


Using built-In 4GL functions

To complete this latest change to the procedure, you need to define the statement that checks whether the ShipDate is Unknown, and then picks out the month from the date, using the cMonthList variable you defined just above, and converts it to one of the three-letter abbreviations in the list. Here is the whole statement:

IF ShipDate NE ? THEN 
DISPLAY ENTRY(MONTH(ShipDate), cMonthList) LABEL "Month". 

Now take a closer look at the elements in the DISPLAY statement. First there is a new keyword, ENTRY. This is the name of a built-in function in the 4GL. There are many such functions to do useful jobs for you, to save you the work of writing the code to do it yourself. The ENTRY function takes two arguments, and as you can see, those arguments are enclosed in parentheses. The first is an INTEGER value, which identifies an entry in a comma-separated list of character values. In this case it represents the month of the year, from 1 to 12. The second argument is the list that contains the entry the function is retrieving. In this case it is the variable you just defined.

Looking closer, you can see that the first of the two arguments to the function, MONTH(ShipDate), is itself another function. This function takes a Progress DATE value as an argument, extracts the month number of the date, and returns it. The returned value is an INTEGER from 1 to 12 that the ENTRY function then uses to pick out the right entry from the list of months in cMonthList. So if the month is May, the MONTH function returns 5 and the ENTRY function picks out the fifth entry from the list of months and returns it to the DISPLAY statement.

Here are some general observations about built-in functions:

To display the month along with each Order:

  1. Add the new statement with the function references into your procedure, inside the block of code that loops through the Orders:
  2. DEFINE VARIABLE cMonthList AS CHARACTER  NO-UNDO 
        INIT "JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC". 
    FOR EACH Customer WHERE State = "NH" BY City: 
        DISPLAY CustNum NAME City. 
        FOR EACH Order OF Customer: 
            DISPLAY OrderNum LABEL "Order"  
                OrderDate 
                ShipDate FORMAT "99/99/99" WITH CENTERED. 
            IF ShipDate NE ? THEN 
                DISPLAY ENTRY(MONTH(ShipDate), cMonthList) LABEL "Month". 
        END. 
    END. 
    

  3. To see the effect of the new code, rerun the procedure:
  4. Note: Several separate 4GL DISPLAY statements contribute to the display of fields in a single line for each Order. This is one of the powerful and flexible characteristics of the 4GL. Progress can gather together a number of different statements in a procedure, some of which might be executed conditionally, and combine them together into a single operation such as this. This feature is generally not possible with other programming languages.

  5. To save your procedure, press F6.

Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095